package com.qingrongby.shop.validators;

import com.qingrongby.shop.dto.PersonDTO;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

public class PasswordValidator implements ConstraintValidator<PasswordEqual, PersonDTO> {

    private Integer min;

    private Integer max;

    @Override
    public boolean isValid(PersonDTO personDTO, ConstraintValidatorContext constraintValidatorContext) {
        if (personDTO.getPassword1().isEmpty() || personDTO.getPassword2().isEmpty()){
            return  false;
        }
        boolean match = personDTO.getPassword1().equals(personDTO.getPassword2());
        return match;
    }

    @Override
    public void initialize(PasswordEqual constraintAnnotation) {
        this.min=constraintAnnotation.min();
        this.max=constraintAnnotation.max();
    }
}
